﻿using Api.Shared.Model.Fafu;
using Api.Shared.Model.Impl;
using Api.Shared.Responsitory.Mysql;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;

namespace FitterTest.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [AllowAnonymous]
    [EnableCors("any")]
    public class MysqlTestController : ControllerBase
    {
        private readonly MysqlRespository<Student> respository;
        private readonly MysqlRespository<ParamFengtousMysql> respositoryFt;
        private readonly IMapper mapper;

        public MysqlTestController(
            MysqlRespository<Student> respository,
            MysqlRespository<ParamFengtousMysql> respositoryFt,
            IMapper mapper
        )
        {
            this.respository = respository;
            this.respositoryFt = respositoryFt;
            this.mapper = mapper;
        }

        [HttpGet]
        public IActionResult InsertStu()
        {
            Student student = new() { Age = "12", Name = "ddd" };

            respository.Insert(student);
            return Ok();
        }

        [HttpGet]
        public async Task<ActionResult<ParamFengtousMysql>> GetFengtouDto()
        {
            var fengtous = await respositoryFt.GetByIdAsync(1);

            var dtos = mapper.Map<ParamFengtousMysql>(fengtous);
            return dtos;
        }

        [HttpGet]
        public IActionResult GetIndex()
        {
            //测试新特性
            List<ParamFengtousMysql> fengtousMysqls = [];
            int[] row0 = [1, 2, 3];
            int[] row1 = [3, 2, 3];
            int[] row2 = [5, 2, 3];
            //int[] one = row0.Concat(row1).Concat(row2).ToArray();
            int[] one = [.. row0, .. row1, .. row2];
            var range = Enumerable.Range(1, 100);
            var c = range.Aggregate((a, b) => a + b);
            PersonsList personsList = new(50);
            //personsList[30]

            return Ok(c);
        }
    }
}
